// pages/auth/index.js
import {request} from "../../request/index.js";
import regeneratorRuntime, { async } from "../../libs/runtime/runtime";
import {login} from "../../utils/asyncWx.js";
Page({
 async handleGetUserInfo(e){
   //获取用户信息
   const {encryptedData,rawData,iv,signature}=e.detail;
   //获取小程序登录成功后的code
  const {code}= await login();
  // 发送请求获取用户的token
  const loginParams={ encryptedData,rawData,iv,signature,code};
  //console.log(loginParams);
  const res=await request({url:"/users/wxlogin",data:loginParams,method:"post"});
  //token获取不到,所以自己赋值。
  let token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo";
  wx.setStorageSync('token', token);
  wx.navigateBack({
    delta:1
  })
}
})